package com.b2b2c.store.single.controller;


import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.b2b2c.store.single.entity.GoodsClass;
import com.b2b2c.store.single.logic.GoodsClassLogic;
import com.b2b2c.until.AjaxMap;
import com.b2b2c.until.IsLogin;
import com.b2b2c.validate.context.CheckParam;

/**
  *   商品分类控制器
 * @author Administrator
 */
@RestController
public class GoodsClassController 
{
	@Autowired
	private HttpServletRequest req;
	
	
	@Resource
	private RedisTemplate<String, List<GoodsClass>> redisTemplate;
	
	/**
	  *   商品分类 
	 * @return
	 */
	@RequestMapping("GoodsClass/getClassById")
	public Map<String, ?> classList() {
		
		if (!IsLogin.checkLogin(this.req)) {
			
			return AjaxMap.getInstance("未登录").notLoggedIn();
		}
		
		GoodsClassLogic goodsClassLogic = new GoodsClassLogic(req);
		
		
		CheckParam check = new CheckParam(goodsClassLogic.getValidateRule(), goodsClassLogic.getMap());
		
		if (!check.checkParam()) {
			return AjaxMap.getInstance(check.getErrorMessage()).getAjaxResultMessage();
		}
		
		List<?> classList = goodsClassLogic.getClassList(redisTemplate);
		
		return AjaxMap.getInstance(classList).getAjaxResultByMap();
		
	}
}
